package de.dhbw.karlsruhe.picsim;

import de.dhbw.karlsruhe.picsim.gui.MainWIndowBuilder;
import de.dhbw.karlsruhe.picsim.util.impl.LoggingExceptionHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.swing.*;
import java.io.IOException;
import java.util.logging.LogManager;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: Apr 9, 2010
 * Time: 1:13:21 PM
 */

public final class MainClass {
    private static final Log log = LogFactory.getLog(MainClass.class);


    private MainClass() {
    }

    public static void main(final String[] args) throws Exception {
        configureLogging();
        configureErrorHandling();

        buildUpGui();
        log.info("main thread completed");


    }

    private static void buildUpGui() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                final MainWIndowBuilder builder = new MainWIndowBuilder();
                builder.buildMainWindow();
            }
        });
    }

    private static void configureErrorHandling() {
        Thread.setDefaultUncaughtExceptionHandler(new LoggingExceptionHandler());
    }

    private static void configureLogging() throws IOException {
        LogManager.getLogManager().readConfiguration(MainClass.class.getResourceAsStream("logging.properties"));
    }

}
